package com.feicheng.controller.admin;

import com.alibaba.fastjson.JSONObject;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.service.a.FDzService;
import com.feicheng.service.a.FYyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/dz")
public class DzController {

    @Autowired
    FDzService dzService;
    @Autowired
    FYyService yyService;

    @GetMapping("/page")
    public ResultInfo getByPage(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "12") Integer size,
            String searchKey
    ) {
        JSONObject param = new JSONObject();
        param.put("current", current);
        param.put("size", size);
        param.put("sname", searchKey);
        param.put("tel", searchKey);
        param.put("dname", searchKey);
        param = dzService.getDzsByPage(param);
        return ResultInfo.success(param.get("dzpage"));
    }

    @PutMapping("/info")
    public ResultInfo updateInfo(@RequestBody JSONObject param) {
        return ResultInfo.success(dzService.updateDz(param));
    }

    @GetMapping("/info")
    public ResultInfo getInfo(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "12") Integer size,
            String dzid) {
        JSONObject param = new JSONObject();
        param.put("dzid", dzid);
        param.put("current", current);
        param.put("size", size);
        param = dzService.getDzDetail(param);
        return ResultInfo.success(param);
    }

}
